﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using TFSAccess;

namespace CreateConnectedTask
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        string server = string.Empty;
        string project = string.Empty;
        TFSAccess _TFS = null;
        SelectDestinationServerPart m_part;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TeamProjectPicker workitemPicker = null;
            try
            {

                workitemPicker = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false, new UICredentialsProvider());
                workitemPicker.AcceptButtonText = "Ok";
                workitemPicker.SetDefaultSelectionProvider(DefaultServerSelectionPicker.Instance);
                
                workitemPicker.ShowDialog();
                if (workitemPicker.SelectedProjects != null || workitemPicker.SelectedProjects.Length > 0)
                {
                    server = workitemPicker.SelectedTeamProjectCollection.Uri.ToString();
                    project = workitemPicker.SelectedProjects[0].Name;
                    TfsTeamProjectCollection coll = workitemPicker.SelectedTeamProjectCollection;
                    _TFS = new TFSAccess(server, project, coll);
                    txtTfsServerCollection.Text = server;
                    txtTfsServerProject.Text = project;
                }
            }
            catch (System.NullReferenceException)
            { }
            catch (ArgumentOutOfRangeException)
            { }
            catch (IOException ex)
            {
            }
        }

        private void btnGenerateTask_Click(object sender, RoutedEventArgs e)
        {
            string errorMessage = string.Empty;
           
            IWorkItem workitem = new WorkItemBase(_TFS);
            txtResult.Text = string.Empty;
            txtResult.Text = errorMessage;
        }
    }
}
